// Figure 2
	use "$dir\DataSCLB", clear
	// Keep observations with baseline information:
		keep if BL_P1!=.
	// Rename Variables to loop easier
		rename BL_P1                BL_Score
		rename EL_EGRA_PCA_Index    EL_Score
	// Split in quartiles
		// Loop replaces quartile and prioritizes on smaller quartiles to deal with the zeros
		foreach line in BL EL {
			forvalues treat = 0/2 {
					gen Q_`line'_`treat' = .
						sum `line'_Score if Study_Arm==`treat', d // Quartiles within study arm
						
						replace Q_`line'_`treat' = 1 if Study_Arm==`treat' & Q_`line'_`treat'==. &  `line'_Score <= r(p25)
						replace Q_`line'_`treat' = 2 if Study_Arm==`treat' & Q_`line'_`treat'==. & (`line'_Score > r(p25) & `line'_Score <= r(p50))
						replace Q_`line'_`treat' = 3 if Study_Arm==`treat' & Q_`line'_`treat'==. & (`line'_Score > r(p50) & `line'_Score <= r(p75))
						replace Q_`line'_`treat' = 4 if Study_Arm==`treat' & Q_`line'_`treat'==. & (`line'_Score > r(p75) & `line'_Score <.)			
				}
		}	
	// Aggregate across Treatment Arms
		// Identify those that end up in last quartile in the Endline in every treatment.
			gen q4 = (Q_EL_0==4 |  Q_EL_1==4 | Q_EL_2==4) 
		// Identify the Baseline quartile. (rowtotal just to aggregate across treatments)	
			egen BL_q = rowtotal(Q_BL_0 Q_BL_1 Q_BL_2)
			
	// Graph only for within. 
	// Collapse
			collapse q4 , by(Study_Arm BL_q)
		// Do graphs
	
				// move to 1.5
				replace BL_q = 1.5 if BL_q == 1

				# delimit ;
				twoway (connected q4  BL_q if Study_Arm==0, lp(dash) ms(O))
					   (connected q4  BL_q if Study_Arm==1, lp(dash_dot) ms(D))
					   (connected q4 BL_q if Study_Arm==2, lp(solid) ms(T)), 
						xtitle("Quartile in Baseline") 
						ytitle("") subtitle("Percentage in 4th Quartile at Endline", justification(left) margin(b+1 t-1) bexpand) 
						ylabel(0(0.1)0.6, angle(horizontal) format("%02.1f")) title("")
						xlabel(1.5 "1 & 2" 2 " " 3 "3" 4 "4",notick)
						xscale(range(1(0.5)4.5))
						graphr(c(white)) sch(s2mono) 
						legend(label(1 "Control") label(2 "Reduced-Cost") label(3 "Full-Cost"));
				# delimit cr
		graph export "$output/Figure2.pdf", replace
